package com.v0710.docommon.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.event.ApplicationStartedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;

@Slf4j
@Configuration
@Order(Ordered.HIGHEST_PRECEDENCE)
public class StartedListener implements ApplicationListener<ApplicationStartedEvent> {

    @Override
    public void onApplicationEvent(ApplicationStartedEvent event) {
        this.printStartInfo();
    }

    private void printStartInfo() {
        Runtime runtime = Runtime.getRuntime();
        long maxMemory = runtime.maxMemory();
        long totalMemory = runtime.totalMemory();
        long freeMemory = runtime.freeMemory();

        log.info("最大内存:               {}", maxMemory/1024/1024+"M,"+maxMemory/1024+"KB");
        log.info("总共内存:               {}", totalMemory/1024/1024+"M,"+totalMemory/1024+"KB");
        log.info("可用内存:               {}", freeMemory/1024/1024+"M,"+freeMemory/1024+"KB");
        log.info("App started at         {}", "ok");

    }

}
